package com.stedu.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.stedu.bean.Admin;
import com.stedu.exception.SteduException;
import com.stedu.mapper.AdminMapper;
import com.stedu.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin login(String username, String password) throws SteduException {
        Admin admin = adminMapper.selectByUsername(username);
        if (admin == null){
            throw new SteduException("用户名错误，请重新登录");
        }
        //对用户输入的密码进行加密，两次MD5加密
        String s = SecureUtil.md5(SecureUtil.md5(password));
        if (!s.equals(admin.getPassword())){
            throw new SteduException("密码错误，请重新登录");
        }
        return admin;
    }

    @Override
    public List<Map<String, Object>> selectTop5Dept() {
        return adminMapper.selectTop5Dept();
    }

    @Override
    public List<Map<String, Object>> selectClassNumber() {
        return adminMapper.selectClassNumber();
    }

    @Override
    public Admin selectById(Integer id) {
        return adminMapper.seleById(id);
    }
}
